package com.github.raffle.behavior.mediator;

import java.util.List;
import java.util.Map;

/**
 * 中介
 * @author Stephen Liu
 * @since Jan 28, 2016
 * @version 1.0.0
 */
public abstract class Mediator {
	/**
	 * 持有多个同事
	 */
	protected Map<String, Colleague> colleagues;
	protected Map<String, List<Colleague>> relations;
	
	/**
	 * 添加同事
	 * @param name 同事的名字
	 * @param colleague 同事
	 */
	public void addColleague(String name, Colleague colleague) {
		if (!colleagues.containsKey(name)) {
			//和中介建立关联
			colleague.setMediator(this);
			colleagues.put(name, colleague);
		}
	}
	
	/**
	 * 移除同事
	 * @param name
	 * @param colleague
	 */
	public void removeColleague(String name, Colleague colleague) {
		if (colleagues.containsKey(name)) {
			colleagues.remove(name);
		}
	}

	/**
	 * 
	 * @param name 同事名称
	 * @param method 同事执行的方法
	 */
	public abstract void execute(String name, String method); 
}
